/**
 * 
 */
package me.myachievements.web.tag;

import me.myachievements.persistence.goal.Goal;
import me.myachievements.persistence.tag.Tag;
import me.myachievements.persistence.tag.TagPersistenceManager;

import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.apache.wicket.validation.validator.StringValidator;

/**
 * @author besseym
 *
 */
public class TagForm extends Form<Tag> {
	
	@SpringBean(name="tagPersistenceManager")
	TagPersistenceManager tagPersistanceManager;

	/**
	 * Constructor
	 * @param id
	 * @param tag
	 */
	public TagForm(String id, Tag tag) {
		super(id, new CompoundPropertyModel<Tag>(tag));
		addComponents();
	}
	
	/**
	 * Constructor
	 * @param id
	 * @param iModel
	 */
	public TagForm(String id, IModel<Tag> iModel){
		super(id, new CompoundPropertyModel<Tag>(iModel));
		addComponents();
	}
	
	/**
	 * 
	 */
	private void addComponents(){
		add(new TextField<String>("value").setRequired(true).add(StringValidator.maximumLength(50)));
	}
	
	/**
	 * 
	 */
	@Override
	protected void onSubmit(){
		Tag tag = this.getModelObject();
		tagPersistanceManager.create(tag);
	}

}
